#/usr/bin/python
from util import *

class ServiceParser:
    def __init__(self):
        self.util=Util()
    def init(self,package,domain,sentence):
        self.domain=domain
        self.sentence=sentence
        self.package=package
        parser=InterfaceParser(domain)
        self.interfacetable=parser.get_interface_table(sentence)
    def gen_interface_method(self):
        interfacestr=""
        for interface in self.interfacetable:
            interfacestr=interfacestr+"\n"+interface.gen_interface()
        return interfacestr
    def gen_service_method(self):
        method_str=""
        for method in self.interfacetable:
            method_str=method_str+"\n"+method.gen_method()
        return method_str
    def gen_interface(self):
        interface="package "+self.package+";\n"
        interface=interface+"public interface "+"I"+self.domain+"Service{\n"
        interface=interface+self.gen_interface_method()
        interface=interface+"}"
        return interface
    def gen_service(self):
        servicestr="package"+self.package+";\n"
        servicestr=servicestr+"@Component(\""+self.util.domain_to_firstlowercase(self.domain)+"Service\")\n"
        servicestr=servicestr+"public class "+self.domain+"ServiceImpl{"
        servicestr=servicestr+self.gen_service_method()
        servicestr=servicestr+"\n}"
        return servicestr
        

if __name__=="__main__":
    dao_file="id:insertSelectItem,parameter:SelectItem select,return: int |id:insertSelectItems,parameter:List<SelectItem> selects,return: int |id:selectSelectItemsbySid,parameter:Long sid,parameter:int id,return: List<SelectItem> |id:deleteItemsbyItemId,parameter:Long itemId,return: int|id:deleteItemBySid,parameter:Long sid,return: int"
    parser=ServiceParser()
    parser.init("com.trendata","SelectItem",dao_file)
    #print(parser.gen_interface())
    print(parser.gen_service())

    
